These small samples shows how you can write code work with EPT document from a Content Studio Web page.
Create an EPT document
The following code snippet shows how easy it is to create a new EPT document by
using
The
int categoryId = 168;
try
{
using(septd = new SyncronizedEPTDocument(CS_ConnectionId,
CS_UserSessionId,
categoryId,
"My news item"))
{
//Add data to the fields
septd["Header"] = "An exciting event";
septd["Intro"] = "This is the introduction";
septd["Text"] = "This is the actual text";
//Create the document
septd.Save();
//Publish it by using the approve method
septd.Approve();
septd.Close();
}
Response.Write("The document has been created successfully");
}
catch(Exception ex)
{
Response.Write("Could not create the document: " + Server.HtmlEncode(ex.Message));
}
Dim categoryId As Integer = 168
Try
Using septd As New SyncronizedEPTDocument(CS_ConnectionId, _
CS_UserSessionId, _
categoryId, _
"My news item")
'Add data to the fields
septd("Header") = "An exciting event"
septd("Intro") = "This is the introduction"
septd("Text") = "This is the actual text"
'Create the document
septd.Save()
'Publish it by using the approve method
septd.Approve()
septd.Close()
End Using
Response.Write("The document has been created successfully")
Catch ex As Exception
Response.Write("Could not create the document: " & Server.HtmlEncode(ex.Message))
End Try
Update the value of an EPT document field
As with the preceding example you can use the
Note
The metadata fields of the EPT document is maintained by Content Studio based on
the meta data of the document and does not exists in the standard fields collection
of the
-
GetMetaFieldAsString -
GetMetaFieldAsDateTime -
GetMetaFieldAsInteger
The sample demonstrates this by reading the CS_PublishData meta data field of the actual document and write it out on the page.
C#int documentID = 4372;
using (SyncronizedEPTDocument septd = new SyncronizedEPTDocument(CS_ConnectionId,
CS_UserSessionId,
documentID))
{
//Update the content of a EPT field named "Header"
septd["Header"] = "An exciting event updated";
septd.Save();
//Get the publish date of the document from one of the meta data fields and print it.
DateTime dt = septd.GetMetaFieldAsDateTime("CS_PublishDate");
Response.Write("The document was published at " + dt.ToString());
}
Dim documentID As Integer = 4372
Using septd As New SyncronizedEPTDocument(CS_ConnectionId, _
CS_UserSessionId, _
documentID)
'Update the content of a EPT field named "Header"
septd("Header") = "An exciting event updated"
septd.Save()
'Get the publish date of the document from one of the meta data fields and print it.
Dim dt As DateTime = septd.GetMetaFieldAsDateTime("CS_PublishDate");
Response.Write("The document was published at " + dt.ToString())
End Using
Create new documents and reuse the schema
This sample shows a more advanced usage of theFor efficency, the schema is reused between the two creation operations and in order to be able to supply a parent document to the second document, a
try
{
int categoryID = CS_InsertedCategoryId;
int parent = 0;
SchemaFieldCollection schema = null;
using(SyncronizedEPTDocument septd = new SyncronizedEPTDocument(CS_ConnectionId,
CS_UserSessionId,
categoryID,
"My news item"))
{
//Add some text
septd["Header"] = "An exciting event";
septd["Intro"] = "This is the introduction";
septd["Text"] = "This is the actual text";
septd.Save();
septd.Approve();
//Save the schema so it can be reused for efficency.
//By doing this Content Studio does not have to reload the same schema
//and build the same field collection again.
schema = septd.SchemaFields;
//Get the document id so we can use it as parent document later
parent = septd.DocumentID;
septd.Close();
}
//Create a second, child document
using(SyncronizedEPTDocument septd = new SyncronizedEPTDocument(CS_ConnectionId,
CS_UserSessionId,
categoryID,
"My child item",
schema))
{
//Add some text
septd["Header"] = "Another exciting event";
septd["Intro"] = "This is another introduction";
septd["Text"] = "This is another actual text";
//document properties such as ParentDocumentID can be
//supplied by using the CSDocument class
CSDocument props = new CSDocument();
props.ParentDocumentID = parent;
septd.Save(props);
septd.Approve();
septd.Close();
}
Response.Write("Success");
}
catch(Exception ex)
{
Response.Write("Failed: " + Server.HtmlEncode(ex.Message));
}
Try
Dim categoryID As Integer = CS_InsertedCategoryId
Dim parent As Integer = 0
Dim schema As SchemaFieldCollection = Nothing
Using septd As New SyncronizedEPTDocument(CS_ConnectionId, _
CS_UserSessionId, _
categoryID, _
"My news item")
'Add some text
septd("Header") = "An exciting event"
septd("Intro") = "This is the introduction"
septd("Text") = "This is the actual text"
septd.Save()
septd.Approve()
'Save the schema so it can be reused for efficency.
'By doing this Content Studio does not have to reload the same
'schema and build the same field collection again.
schema = septd.SchemaFields
'Get the document id so we can use it as parent document later
parent = septd.DocumentID
septd.Close()
End Using
'Create a second, child document
Using septd As New SyncronizedEPTDocument(CS_ConnectionId, _
CS_UserSessionId, _
categoryID, _
"My child item", _
schema)
'Add some text
septd("Header") = "Another exciting event"
septd("Intro") = "This is another introduction"
septd("Text") = "This is another actual text"
'document properties such as ParentDocumentID can be
'supplied by using the CSDocument class
CSDocument props = new CSDocument()
props.ParentDocumentID = parent
septd.Save(props)
septd.Approve()
septd.Close()
End Using
Response.Write("Success")
Catch ex As Exception
Response.Write("Failed: " & Server.HtmlEncode(ex.Message))
End Try
Update properties of a document
You cannot update the metadata fields in an EPT document since these fields are
generated automatically when the document is saved by Content Studio. Instead you
update properties on the document itself and all properties to update must be supplied
in a
Starting with Content Studio version 5.1 there is a possibility to change the FileExtension of an EPT document as well. In earlier versions of the product the file extension for EPT documents where hardcoded to .xml but version 5.1 changes this so that the allowed file extension is controlled by a policy in global policy file. By default only the .ept and .xml file extensions are allowed but this can be further restricted by a category level policy. For more information concerning document policies see Security or Security policies
The following sample shows how to update change the FileExtension and the Keywords of an EPT document
int documentID = 4372;
using (SyncronizedEPTDocument septd = new SyncronizedEPTDocument(CS_ConnectionId,
CS_UserSessionId,
documentID))
{
//Update the file extension and the keywords of an EPT document
CSDocument props = new CSDocument();
props.FileExtension = ".ept";
props.Keywords = "Music, violin, piano, sonata";
septd.Save(props);
septd.Approve();
septd.Close();
}
Dim documentID As Integer = 4372
Using septd As SyncronizedEPTDocument = New SyncronizedEPTDocument(CS_ConnectionId, _
CS_UserSessionId, _
documentID)
'Update the file extension and the keywords of an EPT document
Dim props As New CSDocument()
props.FileExtension = ".ept"
props.Keywords = "Music, violin, piano, sonata"
septd.Save(props)
septd.Approve()
septd.Close()
End Using